package 栈;

import java.util.Stack;

/**
 * @Author：小鹿爱吃鱼
 * @Date: 2025/5/4 21:52
 * @Description:
 */
public class 每日温度 {


    public static int[] dailyTemperatures(int[] temperatures) {
        //小压大
        int [] result  = new int[temperatures.length];
        Stack<Integer> stack = new Stack<>();
        for(int i = 0; i < temperatures.length; i++){
            while(!stack.isEmpty() && temperatures[i] > temperatures[stack.peek()]){
                Integer pop = stack.pop();
                result[pop] = i - pop; // 结算的是弹出来的元素的下标!!!
            }
            stack.push(i);
        }
        return result;
    }

    public static void main(String[] args) {

    }


}
